home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13573 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.2 KB  |  189 lines

  1. Path: news.smartt.com!usenet
  2. From: kparkin@smartt.com (The REFEREE)
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP !! Please !! Read Me !!!!
  5. Date: Tue, 26 Mar 1996 04:01:50 GMT
  6. Organization: Student@BCIT
  7. Message-ID: <4j7prk$j0h@ktk2.smartt.com>
  8. NNTP-Posting-Host: burn-m035.smartt.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hello there fellow C++ programmers,
  12.  
  13. I am new here and I don't quite know how thing work in this group yet,
  14. but I was wondering if there is some nice person out there that is
  15. willing to help me with a small program that I am writing.
  16.  
  17. Also, if there are any "hacker" who just want a small program to play
  18. with and make...feel free to help me out as well.  
  19.  
  20. I will greatly appricieate it.  (Please read this whole document.  I
  21. have added personal notes in the middle and at the very end of this
  22. posting )
  23.  
  24. Here is the specs of the assignment :
  25.  
  26. ++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. Objectives:
  28.  
  29. --> Design a procedural program using C++ iostreams, and reference
  30. parameters.
  31. --> Create a simple binary search tree.
  32.  
  33. Method:
  34.  
  35. Here is where you get another crack a building a binary tree and this
  36. time you just have to build the tree in memory. The program reads an
  37. arbitrary text file, parses each word from the file,  and inserts the
  38. word into a binary search tree.  After the file has been read, the
  39. user can print the tree in order, or search for a specific word in the
  40. tree. Specifically:
  41.  
  42. 1) The user can specify which text file the program reads either as a
  43. command line parameter or in response to a prompt from the program. If
  44. the user specified file does not exist, then the program shall
  45. terminate with an appropriate error message.
  46. 2) The program shall parse the text file for words. A word is any
  47. sequence of characters separated by blanks. Each word is added to the
  48. binary search tree. In the case of duplicate words, a word count shall
  49. be incremented.
  50. 3) Once the file is read, the program prompts the user for a command.
  51. The program shall support 3 commands:
  52. ╖ quit - terminate the program
  53. ╖ print - print the search tree in order. Each word is printed, along
  54. with its occurrence count.
  55. ╖ find - find a specific word. If the word is found, it is printed
  56. along with its occurrence count.
  57.  
  58. Here is the header file tree.h:
  59.  
  60. #ifndef _TREE_H
  61. #define    _TREE_H
  62.  
  63. typedef struct _TNODE {
  64.     char     *string;
  65.     int    cnt;
  66.     struct _TNODE * left;
  67.     struct _TNODE * right;
  68. } TNODE;
  69.  
  70. typedef TNODE * TNODE_PTR;
  71.  
  72. //------------------------------------------
  73. // takes a character string and constructs
  74. // a correctly initialized TNODE. Returns a 
  75. // pointer to the newly created TNODE.
  76. //
  77. TNODE_PTR    tnMake(char *);
  78. //-------------------------------------------
  79. // takes a root pointer to a binary search 
  80. // tree and recursively prints it in order.
  81. //
  82. void         tnPrint(TNODE_PTR);
  83. //-------------------------------------------
  84. // prints a single TNODE, prints string and
  85. // the count.
  86. //
  87. void        tnPrintNode(TNODE_PTR);
  88. //-------------------------------------------
  89. // searches the binary search tree for a
  90. // specific TNODE with a string matching the
  91. // character string. Returns a pointer to the
  92. // node if found, otherwise returns NULL.
  93. //
  94. TNODE_PTR     tnFind(TNODE_PTR, char *);
  95. //--------------------------------------------
  96. // add a word to the binary search tree. If
  97. // the word does not already exist in the tree
  98. // then add a new TNODE to the tree, otherwise
  99. // simply increment the count of the matching
  100. // TNODE.
  101. //
  102. void         tnAdd(TNODE_PTR&, char *);
  103.  
  104. #endif
  105.  
  106. ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  107.  
  108. I also have included a bit of code called prompt.ccp and promt.h.
  109. Please use these codes and add to them to create this program.
  110.  
  111. ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  112.  
  113. PROMPT.CPP
  114.  
  115. #include "prompt.h"
  116.  
  117. char *prompt(char *msg)
  118. {
  119.     static char  cmdBuff[80]="";
  120.     static char     *buffPtr = cmdBuff;
  121.     char * token;
  122.  
  123.     token = strtok(buffPtr, "\n\t ");
  124.     while (token == NULL)
  125.     {
  126.         buffPtr = cmdBuff;
  127.         cout << msg;
  128.         if(!cin.getline(cmdBuff, 80))
  129.         {
  130.             cout << endl << "Input Error: program exit" << endl;
  131.             exit(1);
  132.         }
  133.         else
  134.         {
  135.             token = strtok(buffPtr, "\n\t ");
  136.             buffPtr = NULL;
  137.         }
  138.     }
  139.  
  140.     return token;
  141. }
  142.  
  143. ++++++++++++++++++++++++++++++++++++++++++++++++++++
  144.  
  145. PROMPT.H
  146.  
  147. #ifndef _PROMPT_H
  148. #define _PROMPT_H
  149. #include <string.h>
  150. #include <iostream.h>
  151. #include <stdlib.h>
  152.  
  153. char *prompt(char *msg);
  154.  
  155. #endif
  156.  
  157. +++++++++++++++++++++++++++++++++++++++++++++++++++++
  158.  
  159. If anyone out there would like to help out....please do.  I am stuck
  160. from here on out.
  161.  
  162. If you can finish this SMALL program, please send me a completed
  163. version with all the files, etc.  Please try to send them to me via.
  164. E-mail or you can also post it back to the Internet.  
  165.  
  166. You will receive credit where it is deserved.
  167.  
  168. I thank you for your time and I hope you will be able to help me out.
  169.  
  170. P.S.  This is not for a finicial gain.  It is an assignment that I was
  171. given in class at school.
  172.  
  173.  
  174.  
  175. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  176. It takes a big man to cry, but it takes a 
  177. bigger man to laugh at that man.  --  Jack Handy
  178. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  179.  
  180. Ken Parkin ( REFEREE on mIRC )
  181.  
  182. E-mail #1 :  kparkin@smartt.com
  183. E-mail #2 :  g1140066@bcit.bc.ca
  184. HmPg #1   :  http://www.studentaccess.com/hp/REFEREE/
  185. HmPg #2 : http://www.soe.bcit.bc.ca/scas/cst/year1/setg/ken/
  186.  
  187. Go Flames Go !!!!!
  188.  
  189.